////初始化并读取国家列表
function initcity(){
    var CHtml='省&nbsp;<select name="user.province" id="province"';
	CHtml+=" onchange=\"getItems(\'province\',\'city\',this.options[this.selectedIndex].text);\">";
	CHtml+="<option value=0 selected=\"selected\">请选择</option></select>";
	CHtml+="&nbsp;市&nbsp;<select name=\"user.city\" id=\"city\"";
	CHtml+=" onchange=\"getItems(\'city\',\'county\',this.options[this.selectedIndex].text);\">";
	CHtml+="<option value=0 selected=\"selected\">请选择</option></select>";
	CHtml+="&nbsp;区县&nbsp;<select name=\"user.county\" id=\"county\"><option value=0 selected=\"selected\">请选择</option></select>";    
	$("#XMLCity").html(CHtml); 
	oxml = loadXML("xml/area.xml");
    getprovince();
}
//创建处理XML的对象，兼容多种浏览器
function loadXML(xmlpath){
    var xmlDoc = null;
    if (window.ActiveXObject){
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    }else
    if (document.implementation && document.implementation.createDocument){
        xmlDoc = document.implementation.createDocument("","",null);
    }else{
        alert('Your browser cannot handle this script.');
    }
    xmlDoc.async = false;
    xmlDoc.load(xmlpath);
    return xmlDoc;
}
//获取省份列表
function getprovince(){
    if($(oxml).find("address > province").size()>0){
        var provinceHtml='';
           $(oxml).find("province").each(function(){
               provinceHtml += '<option>'+$(this).attr("name")+'</option>';
          })
        $(provinceHtml).appendTo("#province");
    }
}

//获取省份的城市
function getItems(itemName,childItem,Cvalue){
    currentItem = $(oxml).find(itemName+"[name='"+Cvalue+"']");
	if (currentItem.children().size()<1){ //防止无市
		$("#county").empty();
	}
	var currentHtml='';
    currentItem.children().each(function(){
         currentHtml += '<option>'+$(this).attr("name")+'</option>';
    })
	$("#"+childItem).empty();
	$(currentHtml).appendTo("#"+childItem);
	if (itemName=="province"){
	    getItems("city","county",currentItem.children(0).attr("name"));
		//alert(currentItem.children().size());
	}
}